package cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

public class Base {
    public void run() {
        System.out.println("running");
    }

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Base.class);
        enhancer.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> {
            System.out.println("run before");
            Object result = methodProxy.invokeSuper(o, objects);
            System.out.println("run after");
            return result;
        });

        Base base = (Base) enhancer.create();
        base.run();
    }
}
